var app = getApp();
Page({
  data: {
    DAY: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"],
    temDay: "星期一",
    sections: ["第一节", "第二节", "第三节", "第四节", "第五节", "第六节", "第七节", "第八节", "第九节", "第十节"],
    section: {},
    hide_dialog: true,
    toast_value: "",
    toastSection: ""
  },
  dayTap(a) {
    this.setData({
      temDay: this.data.DAY[a.currentTarget.dataset.idx],
    })
  },
  onLoad() {
    var struct = {}
    this.data.DAY.forEach(element => {
      struct[element] = {
        "第一节": "",
        "第二节": "",
        "第三节": "",
        "第四节": "",
        "第五节": "",
        "第六节": "",
        "第七节": "",
        "第八节": "",
        "第九节": "",
        "第十节": ""
      }
    })
    this.setData({
      section: struct
    })
    wx.cloud.callFunction({
      name: 'function',
      data: {
        type: "getCourse"
      }
    }).then(res => {
      this.setData({
        section: res.result.data[0]
      })
    })
  },
  dialogCancel() {
    this.setData({
      hide_dialog: true,
      toast_value: ""
    })
  },
  dialogConfirm(e) {
    this.setData({
      ["section." + this.data.temDay + "." + this.data.toastSection]: this.data.input_value,
      hide_dialog: true,
      toast_value: ""
    })
    delete this.data.section._id
    delete this.data.section.class
    console.log(this.data.input_value)
    wx.cloud.callFunction({
      name: 'function',
      data: {
        type: "updateCourse",
        data: this.data.section
      }
    })
  },
  showDialog(e) {
    this.setData({
      hide_dialog: false,
      toastSection: e.currentTarget.dataset.itemname,
      input_value: ""
    })
  },
  changeInput(e) {
    this.setData({
      input_value: e.detail.value
    })
  },
  onShareAppMessage: function () {

  }
})